/**
 * Created by dywu on 2015/9/24.
 */
angular.module('wxplat.template', [
    'ngCookies'
])
    .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
        $stateProvider
            .state('wxplat', {
                'abstract': true,
                url: "/mgr",
                views: {
                    '': {
                        template: '<div ui-view="topbar"></div><div ui-view="main"></div>'
                    },
                    'topbar@wxplat': {
                        templateUrl: template_viewurl + "/topbar.html",
                        controller: 'GetCookieController'
                    },
                    'main@wxplat': {
                        templateUrl: template_viewurl + "/main.html",
                        controller: 'ManagerUserTemplateController'
                    }
                }
            })
        ;
    }])

    //判断cookie
    .controller('GetCookieController', ['$scope', '$state', '$cookieStore', 'LoginService', function ($scope, $state, $cookieStore, LoginService) {
        //console.log('manager GetCookieController');
        var data = $cookieStore.get('manager_cookie');
        //console.log(data);
        if (data == undefined) {
            alert("登陆以失效，请再次登陆！");
            $state.go('login');
        } else {
            $scope.manager_cookie = data;
            //console.log("this is" + data.managername);
        }
        // topbar
        if (typeof topbars != 'undefined') {
            $scope.topbars = topbars;
        }
    }])

    //清除cookie
    .controller('RemoveCookieController', ['$scope', '$state', '$cookieStore', function ($scope, $state, $cookieStore) {
        $cookieStore.remove('manager_cookie');
        $state.go('home.exit');
    }])

    //Manager模板
    .controller('ManagerUserTemplateController', ['$scope', '$state', function ($scope, $state) {
        //console.log(manager_sidebars);
        $scope.sidebars = manager_sidebars;
        $scope.currentPage = 1;
        $scope.pageSize = 8;
        // console.log($scope.sidebars);
    }])
;
